import { defineStore } from 'pinia'
import { fetchData } from '@/utils/fetch'
import { API_URLS } from '@/utils/api'

interface UserData {
  id: number;
  name: string;
  email: string;
  [key: string]: any;
}

interface State {
  count: number;
  userData: UserData | null;
}

export const useStore = defineStore('main', {
  state: (): State => ({
    count: 0,
    userData: null
  }),
  getters: {
    doubleCount: (state: State): number => state.count * 2
  },
  actions: {
    increment(): void {
      this.count++
    },
    async loadUserData(): Promise<void> {
      try {
        this.userData = await fetchData<UserData>(API_URLS.getUser, {}, 500)
      } catch (error) {
        console.error('Error loading user data:', error)
      }
    }
  }
}) 